
var id = getvl("id");

var status = getvl("status");

var userId = sessionStorage.getItem("userId");
//店铺详情
if(userId != null) {
	zbDetail(id, userId);
} else {
	zbDetail(id, '');
}


function zbDetail(id,userId) {
	$("#sellerInfo").html("");
	$('#zbGoodssList').html("");
	$.ajax({
		url: urlcore + "/api/zbDirectSeeding/selectOne?id=" + id+ "&userId=" + userId,
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
			if(data.success == true) {
				var da = data.data;
				var headImg = da.user.headImg ==null ? "http://app.jiagangwangluo.com/api//ATTACHMENT/cab06117-6607-401a-843d-5ac103323fb6/sqz.png" : da.user.headImg;
				var thislist =
					'<dl class="fl clearfix">' +
					'<dt><a href="10.1.0dianpu_detail.html?id=' + da.shopInfo.id + '">' +
					'<img src="' + headImg + '" />' +
					'</a></dt>' +
					'<dd>' +
					'<a href="10.1.0dianpu_detail.html?id=' + da.shopInfo.id + '"><h5>' + da.user.userName + '</h5></a>' +
					'<p>' + da.watchAmount + '人观看</p>' +
					'</dd>' +
					'</dl>';
				$('#sellerInfo').append(thislist);
					if(status==2){
						getMyVideo(da.rtmpAddress, da.flvAddress, da.hlsAddress);
					  //getMyVideo1(da.rtmpAddress, da.flvAddress, da.hlsAddress);	
					}else if(status==3){
						//getMyVideo2(da.vodAddress);
						getMyVideo3(da.appId,da.fileId);
					}
			
                
                $.each(da.goodsList, function(i, n) {

                    var packRate=n.tradePrice*da.packRate;
                    
					var thislist1 =
						'<dl>' +
						'<a href="2.2.0goods_detail.html?id=' + n.id + '&goodsType='+2+'&packRate='+packRate+'&zbDirectSeedingId='+da.id+'&breadcrumbType=5" class="clearfix">' +
						'<dt><img src="' + n.coverUrl + '" /><em>1</em></dt>' +
						'<dd>' +
						'<h4>' + n.goodsTitle + '</h4>' +
						'<h6>&yen;' + packRate + '</h6>' +
						'<span>加入进货车</span>' +
						'</dd>' +
						'</a>' +
						'</dl>';
					$('#zbGoodssList').append(thislist1);

				});
                //弹窗二维码
				$(function() {
					//弹出
					$('.public-chat').on('click', function() {
						$(".public_simi_bg").fadeIn();
					});
					$(".public_simi_bg").on('click', function() {
						$(".public_simi_bg").fadeOut();
					})
					
					//隐藏登录页
					$(".closeLogin").click(function() {
						$(".public_simi_bg1").fadeOut();
					});
					
					
					var focus = da.focusShop == null ? '' : da.focusShop.status;
					//关注店铺
					if(focus == 1) {
						$(".Shoucang").text('取消收藏');
					} else {
						$(".Shoucang").text('收藏店铺');
					}
					//收藏
					$(".Shoucang").click(function() {

						if(userId == '') {
							//显示登录页
							$(".public_simi_bg1").fadeIn();
						} else {
							var id = da.focusShop == null ? '' : da.focusShop.id;

							if($(this).text() == '收藏店铺') {

								if(id == '') {
									//取消关注
									if(!layer.confirm("确认收藏吗?")) {
										return;
									}
									$.ajax({
										url: urlcore + '/api/focusShop/add',
										type: "post",
										contentType: "application/json;charset=utf-8",
										data: JSON.stringify({
											"shopId": da.shopInfo.id,
											"status": 1
										}),
										dataType: "json",
										success: function(data) {
											if(data.success == true) {
												layer.alert("收藏成功");

												//跳转列表页
												window.location.href = "5.0.2zhibo_zhibo.html?id=" + da.id;
											} else if(data.code == 'OVERTIME') {
												var thisUrl = window.location.href;
												if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
													top.window.location.href = "1.0.0denglu.html";
												}
											} else {
												layer.alert(data.msg);
											}

										},
										error: function() {
											layer.alert("error");
										}

									});
								} else {
									//取消关注
									if(!layer.confirm("确认收藏吗?")) {
										return;
									}
									$.ajax({
										url: urlcore + '/api/focusShop/update',
										type: "post",
										contentType: "application/json;charset=utf-8",
										data: JSON.stringify({
											"id": id,
											"status": 1
										}),
										dataType: "json",
										success: function(data) {
											if(data.success == true) {
												layer.alert("收藏成功");

												//跳转列表页
												window.location.href = "5.0.2zhibo_zhibo.html?id=" + da.id;
											} else if(data.code == 'OVERTIME') {
												var thisUrl = window.location.href;
												if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
													top.window.location.href = "1.0.0denglu.html";
												}
											} else {
												layer.alert(data.msg);
											}

										},
										error: function() {
											layer.alert("error");
										}

									});
								}

							} else {

								//关注
								if(!layer.confirm("确认取消收藏吗?")) {
									return;
								}
								$.ajax({
									url: urlcore + '/api/focusShop/update',
									type: "post",
									contentType: "application/json;charset=utf-8",
									data: JSON.stringify({
										"id": id,
										"status": 2
									}),
									dataType: "json",
									success: function(data) {
										if(data.success == true) {
											layer.alert("取消成功");

											//跳转列表页
											window.location.href = "5.0.2zhibo_zhibo.html?id=" + da.id;
										} else if(data.code == 'OVERTIME') {
											var thisUrl = window.location.href;
											if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
												top.window.location.href = "1.0.0denglu.html";
											}
										} else {
											layer.alert(data.msg);
										}

									},
									error: function() {
										layer.alert("error");
									}

								});
							}
						}

					});

				});

			}
		},
		error: function() {
			layer.alert("error");
		}
	});
}

function getMyVideo(rtmp, flv, hls) {

	function getParams(name) {
		var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
		var r = window.location.search.substr(1).match(reg);
		if(r != null) {
			return decodeURIComponent(r[2]);
		}
		return null;
	}
	var rtmp = getParams('rtmp'),
		flv = getParams('flv'),
		m3u8 = getParams('m3u8'),
		live = (getParams('live') == 'true' ? true : false),
		coverpic = getParams('coverpic'),
		width = getParams('width'),
		height = getParams('height'),
		autoplay = (getParams('autoplay') == 'true' ? true : false);
	/**
	 * 视频类型播放优先级
	 * mobile ：m3u8>mp4
	 * PC ：RTMP>flv>m3u8>mp4
	 */

	/**
	 * 属性说明：
	 *
	 * coverpic  {Object|String} src:图片地址，style：default 居中1:1显示 stretch 拉伸铺满，图片可能会变形 cover 等比横向铺满，图片某些部分可能无法显示在区域内
	 *  封面在 ios10 暂时无法生效。
	 */
	var options = {
		rtmp: rtmp || rtmp,
		flv: flv || flv, //增加了一个flv的播放地址，用于PC平台的播放 请替换成实际可用的播放地址
		m3u8: m3u8 || hls,
		coverpic: coverpic || { style: 'cover', src: '//vodplayerinfo-10005041.file.myqcloud.com/3035579109/vod_paster_pause/paster_pause1469013308.jpg' },
		autoplay: autoplay ? true : false,
		live: true,
		//stretch_full:1,
		width: width || '904',
		height: height || '492',
		wording: {
	    2032: "请求视频失败，请检查网络",
	    2048: "请求m3u8文件失败，可能是网络错误或者跨域问题"
                }
	};

	var player = new TcPlayer('id_jgsc_video', options);
	window.qcplayer = player;
}
function getMyVideo1(rtmp, flv, hls) {
	if(rtmp==""&&flv==""&&hls==""){
		layer.alert("直播尚未开始");
		return;
	}
	
	var option = {
	"live_url" : flv,
	"live_url2" : hls,
	"live": true,
	"width" : 295,
	"height" : 479
	
	//...可选填其他属性
	};

    var player = new qcVideo.Player("id_jgsc_video", option);
   /* var barrage = [
	{"type":"content", "content":"hello world", "time":"5"},
	{"type":"content", "content":"居中显示", "time":"1", "style":"C64B03;30","position":"center"}
	];
	player.addBarrage(barrage);*/
	window.qcplayer = player;
}
 

/*function getMyVideo2(vod) {
	 var option = {
    "width": 904,
    "height": 492,
    "definition":240,
    "stretch_patch":true,
   // "stretch_full":1,
    "disable_drag":0,
    "third_video": {
    "urls":{
　　　       40 : vod
        }
    }
};
var player = new qcVideo.Player("id_jgsc_video", option);
}
*/
function getMyVideo3(appid,fileid) {
	var option = {
		"file_id": fileid,
	    "app_id": appid,
	    "width": 904,
	    "height": 492,
	    "definition":240,
	    "disable_drag":0
	};
    var player = new qcVideo.Player("id_jgsc_video", option);
}

function getLogin1() {
	var phone = $('#phone').val().trim();
	if(phone == '') {
		layer.alert("请输入手机号码！");
		return false;
	}
	var password = $('#password').val().trim();
	if(password == '') {
		layer.alert("请输入登录密码！");
		return false;
	}
	$.ajax({
		url: urlcore + "/api/user/loginByPhone",
		type: "post",
		contentType: "application/json;charset=utf-8",
		data: JSON.stringify({
			"phone": phone,
			"password": password
		}),
		dataType: "json",
		success: function(data) {
			if(data.success == true) {
				if(layer.confirm("登录成功！")) {
					
					var da =data.data;
					//var url="index.html?userName="+da.userName;
					//window.location.href = encodeURI(url);
					
					if(window.sessionStorage){
						//登录名
						sessionStorage.setItem("userName",da.userName);
						//登录类型
						sessionStorage.setItem("userType",da.userType);
						sessionStorage.setItem("userId",da.id);
						//设置cookie
						/*var domain_url = urlcore.split('://')[1];
						if (domain_url.indexOf(':') > -1) {
							domain_url = domain_url.split(':')[0];
						}else{
							domain_url = domain_url.split('/')[0];
						}
						document.cookie = "JSESSIONID="+data.data.token+";path=/;domain="+domain_url;*/
						
					//	sessionStorage.setItem("userId",da.id);
						window.location.href="5.0.2zhibo_zhibo.html?id="+id;
					}else{    
						layer.alert("浏览暂不支持sessionStorage");
					} 
					
					//或者 if(typeof window.localStorage == 'undefined'){ 	alert("浏览暂不支持localStorage") }
					//刷新
					//location.reload();
					
				} else {
					//跳转列表页
					window.location.href = "1.0.0denglu.html";
				}
			} else if(data.code == 'OVERTIME') {
				var thisUrl = window.location.href;
				if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
					top.window.location.href = "1.0.0denglu.html";
				}
			} else {
				layer.alert(data.msg);
			}
		},
		error: function() {
			layer.alert("error");
		}

	});
}